<template>
    <div>
        <h2>科室页面(显示)</h2>
        科室名称:<input type="text" v-model="pif.Uname">
        创建时间:<input type="date" v-model="pif.StrTime"> - <input type="date" v-model="pif.EndTime">
        <br> <input type="button" value="查询" @click="ShowTypes">&nbsp;&nbsp;
        <input type="button" value="条件重置" @click="pif.StrTime = null, pif.EndTime = null, pif.Uname = null">&nbsp;&nbsp;
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in pdate.list">
                    <td>{{ item.tname }}</td>
                    <td>{{ item.personNum }}</td>
                    <td>{{ item.thing }}</td>
                    <td>{{ item.strDate.substring(0, 10) }}</td>
                    <td>
                        <input type="button" value="修改" @click="UpdeteType(item.tid)">
                        <input type="button" value="删除" @click="DeleteType(item.tid)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';


const router = useRouter();
const route = useRoute();

let pif = reactive({
    StrTime: null,
    EndTime: null,
    Uname: null,
});
let pdate = reactive({
    list: [],
    ss: 0
})

onMounted(() => {
    ShowTypes();
})

const ShowTypes = () => {
    axios({
        url: '/api/Hotel/ShowType',
        method: 'get',
        params: pif
    }).then((res) => {  
        Object.assign(pdate, res.data); 
    })
}


const DeleteType = (tid: any) => {

     //确认要删除吗
    if (!confirm('确认要删除吗')) { 
        return;
    } 
 
    axios({
        url: '/api/Hotel/DeleteType',
        method: 'put',
        params: { uid: tid }
    }).then((res) => {
        console.log(res.data);
        if (res.data > 0) {
            alert('删除成功');
            ShowTypes();
        }
    })
}




// 修改 跳转
const UpdeteType = (id: any) => {

    //确认要修改吗
    if (confirm('确认要修改吗')) { 
        router.push({ path: "UpdeteType", query: { id: id } })
    }else{
        return;
    }
}



</script>

<style scoped></style>